// Author: Ivan Kazmenko (gassa@mail.ru)
// Generator for problem "swords"
module gen;
import std.algorithm;
import std.conv;
import std.exception;
import std.format;
import std.random;
import std.range;
import std.stdio;

immutable string testFormat = "%03d";
enum generateAnswers = false;

immutable int minC =      1;
immutable int maxC = 10_000;

struct Test
{
	int a, x;
	int b, y;
	int n;

	string comment;

	void validate () const
	{
		enforce (minC <= a && a <= maxC);
		enforce (minC <= x && x <= maxC);
		enforce (minC <= b && b <= maxC);
		enforce (minC <= y && y <= maxC);
		enforce (minC <= n && n <= maxC);
	}

	void print (File f) const
	{
		f.writeln (a, " ", x);
		f.writeln (b, " ", y);
		f.writeln (n);
	}

	string log () const
	{
		return format ("%s (%s %s, %s %s, %s)", comment,
		    a, x, b, y, n);
	}
}

Test [] tests;

void printAllTests ()
{
	foreach (testNumber, test; tests)
	{
		test.validate ();
		auto testString = format (testFormat, testNumber + 1);
		auto f = File (testString, "wt");
		test.print (f);
		static if (generateAnswers)
		{
			auto g = File (testString ~ ".a", "wt");
			test.printAnswer (g);
		}
		writeln (testString, ": ", test.log ());
	}
}

Mt19937 rndLocal;

void main ()
{
	rndLocal.seed (157_159_004);

	tests ~= Test (    1,     2,     4,     3,     3,
	    "example test 1");
	tests ~= Test (    1,     2,     4,     5,     6,
	    "example test 2");

	tests ~= Test (    1,     1,     1,     1,     1,
	    "minimal test");
	tests ~= Test (    1,     2, 10000, 10000,  9999,
	    "min-max test");

	tests ~= Test (    6,     4,     5,     2,   100,
	    "small test");
	tests ~= Test (  100,  1000,     1,    10,    10,
	    "small increasing test");

	tests ~= Test (    6,     2,   121,    19,  1235,
	    "medium parity test");
	tests ~= Test (    9,     3,   121,    94,  4238,
	    "medium impossible test");

	tests ~= Test ( 5123,  9947,  6847,  3516, 10000,
	    "large jumpy test");
	tests ~= Test (    1,     2, 10000, 10000,     2,
	    "maximum answer test");
	tests ~= Test (    1, 10000, 10000,  9999,  9999,
	    "maximum intermediate test");
	tests ~= Test ( 6000,  5970, 10000,  9970,  9998,
	    "maximal impossible test");

	printAllTests ();
}
